package org.mech.sefer.event.register.impl;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.mech.sefer.event.Handler;
import org.mech.sefer.event.register.HandlerRegistrationInfo.Order;
import org.mech.sefer.event.register.HandlerRegistry;

/**
 * <p>
 * The HandlerRegistryImpl is default {@link HandlerRegistry} implementation
 * </p>
 * <p>
 * Date: 24.4.2012 8:49:17
 * </p>
 *
 * @author martin.krajc
 */
public class HandlerRegistryImpl implements HandlerRegistry{
	
	private List<Handler> handlers = new ArrayList<Handler>();

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void register(Handler handler,
			Order order) {
		if(Order.FIRST.equals(order)){
			handlers.add(0, handler);
		} else {
			handlers.add(handler);
		}
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public void unregister(Handler handler) {
		handlers.remove(handler);
	}

	/**
	 * {@inheritDoc}
	 */
	@Override
	public Iterator<Handler> handlers() {
		return handlers.iterator();
	}

}
